package comment_api

import (
	"fmt"
	"gin_study_blog/common"
	"gin_study_blog/common/http"
	"gin_study_blog/models"
	"gin_study_blog/service/redis"
	"github.com/gin-gonic/gin"
)

type CommentDiggRequest struct {
	ID uint `json:"id" form:"id" uri:"id"`
}

func (CommentApi) CommentDIggView(c *gin.Context) {
	var cr CommentDiggRequest
	err := c.ShouldBindUri(&cr)
	if err != nil {
		http.FailWithCode(http.ParamsError, c)
		return
	}

	var comment models.CommentModel
	err = common.DB.Take(&comment, cr.ID).Error
	if err != nil {
		http.FailWithMessage("评论不存在", c)
		return
	}

	redis.NewCommentDiggCount().Set(fmt.Sprintf("%d", cr.ID))

	http.IsOkWithMessage("评论点赞成功", c)
}
